function request(url, data, method) {
  return new Promise(function (resolve, reject) {
    wx.request({
      url: url,
      data: data,
      method: method,
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'token': wx.getStorageSync('token')
      },
      success: function (res) {
        // console.log("------------------------------------------------------------------------------------------");
        // console.log("请求url【"+url+"】");
        // console.log("请求参数【"+JSON.stringify(data)+"】");
        // console.log("返回数据："+JSON.stringify(res));
        resolve(res.data);
      },
      fail: function (res) {
        reject(res);
        console.log("微信网络请求异常");
      }
    })
  }).catch((data) => {});
}

function showSuccessToast(msg) {
  wx.showToast({
    title: msg,
    icon: 'none',
    duration: 1500
  });
}

function showErrorToast(msg) {
  wx.showToast({
    title: msg,
    icon: 'none',
    duration: 1500
  });
}
// 判断是否是手机号码
function isMobile(str) {
  if (str.length != 0) {
    var reg = /^1[0-9][0-9]\d{8}$/;
    if ((reg.test(str))) {
      return true;
    } else {
      return false;
    }
  } else {
    return false;
  }
}


module.exports = {
  request,						//封装的微信request
  showSuccessToast,		//成功消息提示
  showErrorToast,			//失败消息提示
  isMobile
}